<template>
  <div>
    <el-table title="宿舍转出记录" :data="tableData">
      <el-table-column prop="createdTime" label="日期" width="180" :formatter="formatDate">
      </el-table-column>
      <el-table-column prop="studentName" label="姓名" width="100">
      </el-table-column>
      <el-table-column prop="outRoomBuildingName" label="转出楼栋" width="80">
      </el-table-column>
      <el-table-column prop="outRoomName" label="转出房间" width="80">
      </el-table-column>
      <el-table-column prop="inRoomBuildingName" label="转入楼栋" width="80">
      </el-table-column>
      <el-table-column prop="inRoomName" label="转入房间" width="80">
      </el-table-column>
      <el-table-column prop="leaderName" label="审核领导" width="80">
      </el-table-column>
      <el-table-column prop="state" label="状态" width="80">
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total=totalNum>
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {selectOutroomAdjust} from '../../../api/dormitory_admin'

export default {
  data () {
    return {
      pageNo: 1,
      pageSize: 5,
      totalNum: 0,
      DOT: {
        pageNo: 1,
        pageSize: 5,
        data: {
          ID: JSON.parse(localStorage.getItem('user')).id.toString()
        }
      },
      tableData: []
    }
  },
  methods: {
    formatDate (row) {
      const date = new Date(row.createdTime)
      const beijingTime = new Date(date.getTime())
      const year = beijingTime.getFullYear()
      const month = (beijingTime.getMonth() + 1).toString().padStart(2, '0')
      const day = beijingTime.getDate().toString().padStart(2, '0')
      return `${year}年${month}月${day}日`
    },
    handleCurrentChange (newPage) {
      this.DOT.pageNo = newPage
      this.getData()
    },
    getData () {
      selectOutroomAdjust(this.DOT).then(res => {
        this.tableData = res.data
        this.totalNum = res.otherData.totalNum
      })
    }
  },
  created () {
    this.getData()
  }
}
</script>
<style scoped>
</style>
